Lab6 safe Refactoring#42
Open
slavik22 wants to merge 22 commits into
Open
Conversation
Lab2 smells
…for testability - Add ITcpListener interface and TcpListenerWrapper to decouple TcpListener - Extract EchoServer into EchoServer.cs with injected ITcpListener and logger - Extract UdpTimedSender into its own file; move Random to field to avoid per-call allocation - Make HandleClientAsync public and accept Stream for direct unit testing - Reduce Program.cs to entry-point only
…r and UdpTimedSender - EchoServerTests: StartAsync lifecycle, HandleClientAsync echo logic, cancellation, stream exception handling, client connect/disconnect logging - UdpTimedSenderTests: double-start guard, stop without start, restart after stop, dispose lifecycle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Лаба 6 — Безпечний рефакторинг EchoServer під тести
Що зроблено
Рефакторинг:
ITcpListenerінтерфейс +TcpListenerWrapper—EchoServerбільше не залежить відTcpListenerнапрямуHandleClientAsyncзробленоpublicз параметромStreamзамістьTcpClient— метод тепер тестується зMemoryStreamAction<string>— прибрано пряму залежність відConsole.WriteLineProgram.cs(175 рядків, 2 класи) розбито наEchoServer.cs,UdpTimedSender.cs,Program.csRandomперенесено з тіла callback у поле класу — усунуто зайвийnew Random()на кожен викликТести:
EchoTcpServerTestsз 13 юніт-тестамиEchoServerTests— lifecycleStartAsync/Stop, echo-логіка, скасування, обробка виключень стриму, логування підключення/відключення клієнтаUdpTimedSenderTests— захист від подвійного запуску, зупинка без старту, повторний старт після зупинки, lifecycleDisposeМетрики до / після
EchoTcpServerEchoServerTcpListenerConsoleРезультат
Total tests: 13 Passed: 13 Failed: 0